/**
 * Copyright(c)2012 Beijing PeaceMap Co.,Ltd.
 * All right reserved. 
 */
package com.pmc.dwa.security.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;

/**
 * @description 加密工具类
 * @author aokunsang
 * @date 2013-1-7
 */
public final class EncryptUtils {

	/**
	 * 对字符串进行MD5加密
	 * @param str
	 * @return
	 */
	public static synchronized String md5(String str){
		if(StringUtils.isEmpty(str)) return str;
		Md5PasswordEncoder md5Encoder = new Md5PasswordEncoder();
		return md5Encoder.encodePassword(str, "");
	}
	
	/**
	 * 对字符串进行SHA加密
	 * @param str
	 * @return
	 */
	public static synchronized String sha(String str){
		if(StringUtils.isEmpty(str)) return str;
		ShaPasswordEncoder shaEncoder = new ShaPasswordEncoder();
		return shaEncoder.encodePassword(str, "");
	}
	public static void main(String[] args) {
		System.out.println(md5("admin"));
	}
}
